import javax.swing.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-02
 * Time: 5:16
 */
class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class UserException extends RuntimeException{
    public UserException(String message) {
        super(message);
    }
}
class PasswordException extends RuntimeException{
    public PasswordException(String message) {
        super(message);
    }
}
class Login{
    private final String admin="lyh";
    private final String password="123";

    public void func(String admin, String password){
        if(!this.admin.equals(admin)){
            throw new UserException("用户名错误");
        }
        if(!this.password.equals(password)){
            throw new PasswordException("密码错误");
        }
    }
}
public class Test {
    //给异常做笔记
    public static void main(String[] args) {
        try {
            Login login = new Login();
            login.func("lyh","1234");
        }catch (UserException e){
            e.printStackTrace();
        }catch (PasswordException e){
            e.printStackTrace();
        }
        System.out.println("登录成功");
    }
    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try{
            int[] array = null;
            System.out.println(array.length);
        }catch (NullPointerException e){
            System.out.println("这是一个空指针异常");
        }catch (ArithmeticException e){
            System.out.println("这是一个算术异常");
        }finally{
            scanner.close();
            System.out.println("无论程序是否发生异常,finally块内的代码都会执行");
        }
        System.out.println("after try catch");
    }
    public static void main7(String[] args) {
        try{
            int[] array = null;
            System.out.println(array.length);
        }catch (NullPointerException e){
            System.out.println("这是一个空指针异常");
        }catch (ArithmeticException e){
            System.out.println("这是一个算术异常");
        }
    }
    public static void main6(String[] args) {
        try{
            int[] array = null;
            System.out.println(array.length);
        }catch (Exception e){
            System.out.println("我在这里处理了这个异常");
        }
        System.out.println("程序能够继续运行，但是如果交给JVM处理，程序就不会运行到这，会在异常那里立即终止");
    }
    public static void main5(String[] args) {
        int[] array = null;
        if(array == null){
            throw new NullPointerException();
        }
        int[] arr = {1,2,3};
        if(arr.length > 3){
            throw new ArrayIndexOutOfBoundsException();
        }
    }
    public static void func(int a){
        if(a == 0){
            throw new RuntimeException();
        }
    }
    public static void main4(String[] args) {
        func(0);
        System.out.println("其后的代码逻辑");
    }

    public static void main3(String[] args) {
        int a = 10/0;
        System.out.println(a);
    }
        public static void main2(String[] args) throws Exception {
            Person person1 = new Person();
            Person person2 = (Person) person1.clone();
            int a = 10/0;
            System.out.println(a);
        }

    public static boolean checkRecord(String s) {
        int acount = 0;
        int pcount = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == 'A'){
                acount++;
                pcount = 0;
            }
            if(s.charAt(i) == 'P'){
                pcount = 0;
            }
            if(s.charAt(i) == 'L'){
                pcount++;
                if(pcount >= 3){
                    return false;
                }
            }
            if(acount > 2){
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        String s = "PPALLP";
        System.out.println(checkRecord(s));
    }
}
